package com.example.obtaingaode.util;

import android.content.Context;

import com.blankj.utilcode.util.ToastUtils;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;

public class HintUtil {
    private static QMUITipDialog mDialog;
    public static void showErrorStr(String errorStr) {
        ToastUtils.showLong(errorStr);
    }

    public static void showSuccessStr(String successStr) {
        ToastUtils.showLong(successStr);
    }

    public static void showHintStr(String hintStr) {
        ToastUtils.showLong(hintStr);
    }

    public static void showErrorStr(Context context, String errorStr) {
        mDialog = new QMUITipDialog.Builder(context).setIconType(QMUITipDialog.Builder
                .ICON_TYPE_FAIL)
                .setTipWord(errorStr).create();
        mDialog.show();
        dismissDialog();
    }

    public static void showSuccessStr(Context context, String successStr) {
        mDialog = new QMUITipDialog.Builder(context).setIconType(QMUITipDialog.Builder
                .ICON_TYPE_SUCCESS)
                .setTipWord(successStr).create();
        mDialog.show();
        dismissDialog();
    }

    public static void showHintStr(Context context, String hintStr) {
        mDialog = new QMUITipDialog.Builder(context).setIconType(QMUITipDialog.Builder
                .ICON_TYPE_NOTHING)
                .setTipWord(hintStr).create();
        mDialog.show();
        dismissDialog();
    }

    public static void showErrorNet(Context context, String errorStr) {
        mDialog = new QMUITipDialog.Builder(context).setIconType(QMUITipDialog.Builder
                .ICON_TYPE_FAIL)
                .setTipWord(errorStr).create();
        mDialog.show();
        dismissDialog();
    }

    public static  void dismissDialog(){
        Observable.timer(1500, TimeUnit.MILLISECONDS).subscribe(new Consumer<Long>() {
            @Override
            public void accept(Long aLong) throws Exception {
                if(mDialog!=null)
                {
                    mDialog.dismiss();
                    mDialog=null;
                }
            }
        });
    }

}